/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



package sonia.golf.view;

//~--- non-JDK imports --------------------------------------------------------

import android.app.Activity;
import android.app.AlertDialog;

import android.content.DialogInterface;

import android.widget.EditText;

import sonia.golf.R;
import sonia.golf.util.Util;

/**
 *
 * @author Sebastian Sdorra
 */
public abstract class AbstractNewItemDialog
{

  /**
   * Constructs ...
   *
   *
   * @param activity
   */
  public AbstractNewItemDialog(Activity activity)
  {
    this.activity = activity;
  }

  //~--- methods --------------------------------------------------------------

  /**
   * Method description
   *
   */
  protected abstract void onCancel();

  /**
   * Method description
   *
   *
   * @param name
   */
  protected abstract void onOk(String name);

  //~--- get methods ----------------------------------------------------------

  /**
   * Method description
   *
   *
   * @return
   */
  protected abstract int getMessageId();

  //~--- methods --------------------------------------------------------------

  /**
   * Method description
   *
   */
  public void show()
  {
    AlertDialog.Builder dialog = new AlertDialog.Builder(activity);

    dialog.setMessage(getMessageId());

    final EditText nameEdit = new EditText(activity);

    dialog.setView(nameEdit);
    dialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface di, int i)
      {
        String name = nameEdit.getText().toString();

        if (Util.isNotEmpty(name))
        {
          onOk(name);
        }
      }
    });
    dialog.setNegativeButton(R.string.cancel,
                             new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface di, int i)
      {
        onCancel();
      }
    });
    dialog.show();
  }

  //~--- fields ---------------------------------------------------------------

  /** Field description */
  protected Activity activity;
}
